﻿@using YanForum.Engine.ViewModels
@model CommentIndex
@{
    var isAdmin = Request.IsAuthenticated && User.IsInRole(YanForum.Engine.ViewModels.UserRoles.Admin);
}

@if (Model.TotalCount > 0)
{
    <ul class="list-unstyled">
        @foreach (var comment in Model.ListComment)
        {
            <li class="comment-item row">
                @if (isAdmin)
                {
                    <i class="deleteComment glyphicon glyphicon-remove pointer text-red" title="Xóa comment này" data-id="@comment.Id"></i>
                }
                <div class="col-md-12 comment-content media">
                    <div class="c-content media-body">@Html.Raw(comment.CommentPost)</div>
                </div>
                <div class="col-md-12 user-info">
                    <div class="row">
                        <div class="col-md-12">
                            <img class="pull-left img-avatar" src="@comment.UserAvatar" alt="@comment.FullName" />
                            <div class="pull-left">
                                <div><strong>@comment.FullName</strong> - <span class="time text-muted">@comment.TimeAgo</span></div>
                                <div class="c-reply row">
                                    <div class="col-md-6">
                                        <a href="javascript:;" onclick="showCommentPost(this,@comment.Id)">Trả lời</a>
                                    </div>
                                    @if (comment.TotalSubComment > 0)
                                    {
                                        <div class="col-md-6">
                                            <a href="javascript:;" onclick="showSubComment(this,@comment.Id)">Xem @comment.TotalSubComment trả lời khác</a>
                                        </div>
                                    }
                                </div>
                            </div>
                            <div class="clearfix"></div>
                        </div>
                        <!--  FORM SUB COMMENT-->
                        <div class="col-md-12 form-subcomment" id="@("form-subcomment-" + comment.Id)">
                            <form action="#" class="formSubComment">
                                <div class="row">
                                    <div class="col-md-12">
                                        <textarea class="form-control txtSubComment" id="@("txtSubComment_" + comment.Id)" placeholder="Ý kiến của bạn" name="txtSubComment" cols="12" rows="2"></textarea>
                                    </div>
                                    <div class="col-md-12">
                                        <button type="submit" class="btn btn-default pull-right">Gửi</button>
                                    </div>
                                </div>
                            </form>
                        </div>
                        <!-- END FORM SUB COMMENT -->
                    </div>
                </div>
                <div class="sub-comment col-md-12">
                    <!-- Ajax Load SubComment -->
                </div>
            </li>
        }
    </ul>
    if (Model.TotalCount > Model.ListComment.Count)
    {
        string url = Url.Action("AjaxLoadComment", "Comment", new { area = "" });
        <div class="col-md-12 text-center">
            <nav>
                @{Html.RenderAction("Pagging", "Partial", new { area = "", linktext = url + "?contentId=" + Model.ContentId, totalCount = Model.TotalCount, pageSize = Model.PageSize, pageIndex = Model.PageIndex });}
            </nav>
        </div>
    }

}